<template>
  <div class="dashboard-container">
    <!-- 系统功能介绍 -->
    <el-card class="intro-card">
      <template #header>
        <div class="card-header">
          <span>高校教师学术成果信息综合管理系统 - 学生工作台</span>
        </div>
      </template>
      <div class="intro-content">
        <el-row :gutter="30">
          <el-col :xs="24" :sm="12" :md="6">
            <div class="feature-item">
              <div class="feature-icon">
                <el-icon size="40" color="#409EFF"><Edit /></el-icon>
              </div>
              <h3>成果申报</h3>
              <p>便捷提交学术成果，支持论文、专利、项目、获奖等多种类型的成果录入，实现成果信息的标准化管理和提交。</p>
            </div>
          </el-col>
          <el-col :xs="24" :sm="12" :md="6">
            <div class="feature-item">
              <div class="feature-icon">
                                 <el-icon size="40" color="#67C23A"><ViewIcon /></el-icon>
              </div>
              <h3>进度跟踪</h3>
              <p>实时查看成果审核进度，了解审核状态、评审意见和反馈信息，确保及时了解成果处理情况。</p>
            </div>
          </el-col>
          <el-col :xs="24" :sm="12" :md="6">
            <div class="feature-item">
              <div class="feature-icon">
                <el-icon size="40" color="#E6A23C"><Folder /></el-icon>
              </div>
              <h3>成果管理</h3>
              <p>系统化管理个人学术成果档案，支持成果分类查看、历史记录查询和成果统计分析功能。</p>
            </div>
          </el-col>
          <el-col :xs="24" :sm="12" :md="6">
            <div class="feature-item">
              <div class="feature-icon">
                <el-icon size="40" color="#F56C6C"><ChatDotRound /></el-icon>
              </div>
              <h3>互动交流</h3>
              <p>与指导教师进行学术交流，接收审核反馈，获得学术指导，促进学术成果质量的持续提升。</p>
            </div>
          </el-col>
        </el-row>
        
        <div class="student-guide">
          <h3>使用指南</h3>
          <el-row :gutter="20">
            <el-col :span="12">
              <ul class="guide-list">
                <li><strong>成果提交：</strong>按照规范格式提交学术成果，确保信息完整准确</li>
                <li><strong>状态查询：</strong>及时查看成果审核状态，关注评审进度</li>
                <li><strong>反馈处理：</strong>根据评审意见及时修改完善成果内容</li>
              </ul>
            </el-col>
            <el-col :span="12">
              <ul class="guide-list">
                <li><strong>档案管理：</strong>定期整理个人成果档案，建立完整的学术记录</li>
                <li><strong>质量提升：</strong>积极与导师沟通，不断提高学术成果质量</li>
                <li><strong>规范遵守：</strong>严格遵守学术规范，确保成果的真实性和原创性</li>
              </ul>
            </el-col>
          </el-row>
        </div>
      </div>
    </el-card>

    <el-card class="recent-card">
      <template #header>
        <div class="card-header">
          <span>近期提交的学术成果</span>
          <el-button type="primary" size="small" @click="$router.push('/student/achievements')">查看全部</el-button>
        </div>
      </template>
      <el-table v-loading="loading" :data="recentAchievements" style="width: 100%">
        <el-table-column prop="title" label="成果标题" />
        <el-table-column prop="type" label="成果类型" />
        <el-table-column prop="createdAt" label="提交日期" width="180" />
        <el-table-column prop="status" label="审核状态" width="120">
          <template #default="scope">
            <el-tag :type="getStatusType(scope.row.status)">{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, onMounted } from 'vue'
import StudentService from '@/api/student'
import { ElMessage } from 'element-plus'
import { 
  Edit, 
  View as ViewIcon, 
  Folder, 
  ChatDotRound
} from '@element-plus/icons-vue'

interface Achievement {
  id: string
  title: string
  type: string
  createdAt: string
  status: string
}

interface Stats {
  total: number
  pending: number
  approved: number
  rejected: number
}

export default defineComponent({
  name: 'StudentDashboard',
  components: {
    Edit,
    ViewIcon,
    Folder,
    ChatDotRound
  },
  setup() {
    const loading = ref(true)
    const recentAchievements = ref<Achievement[]>([])
    const stats = ref<Stats>({
      total: 0,
      pending: 0,
      approved: 0,
      rejected: 0
    })

    const getStatusType = (status: string) => {
      switch (status) {
        case '待审核':
          return 'info'
        case '已通过':
          return 'success'
        case '已拒绝':
          return 'danger'
        default:
          return ''
      }
    }
    
    const fetchStats = async () => {
      try {
        const response = await StudentService.getAchievementStats()
        stats.value = response.data
      } catch (error: any) {
        console.error('获取统计信息失败:', error)
        ElMessage.error('获取统计数据失败，请稍后再试')
      }
    }
    
    const fetchRecentAchievements = async () => {
      try {
        const response = await StudentService.getMyAchievements()
        // 获取最近的几条数据
        recentAchievements.value = response.data.slice(0, 3)
      } catch (error: any) {
        console.error('获取最近成果失败:', error)
      } finally {
        loading.value = false
      }
    }

    onMounted(() => {
      Promise.all([fetchStats(), fetchRecentAchievements()])
        .catch(() => {
          loading.value = false
        })
    })

    return {
      loading,
      recentAchievements,
      stats,
      getStatusType
    }
  }
})
</script>

<style scoped>
.dashboard-container {
  padding: 20px;
}

.intro-card {
  margin-bottom: 30px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.intro-content {
  padding: 20px 0;
}

.feature-item {
  text-align: center;
  padding: 20px;
  margin-bottom: 20px;
  border-radius: 8px;
  background: #fafbfc;
  transition: all 0.3s ease;
}

.feature-item:hover {
  background: #f0f9ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.feature-icon {
  margin-bottom: 15px;
}

.feature-item h3 {
  margin: 15px 0 10px 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.feature-item p {
  color: #666;
  line-height: 1.6;
  font-size: 14px;
  margin: 0;
}

.student-guide {
  margin-top: 40px;
  padding: 30px;
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  border-radius: 12px;
}

.student-guide h3 {
  margin: 0 0 25px 0;
  font-size: 20px;
  font-weight: 600;
  color: #333;
  text-align: center;
}

.guide-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.guide-list li {
  margin-bottom: 15px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  color: #555;
  line-height: 1.5;
}

.guide-list li:last-child {
  border-bottom: none;
}

.guide-list strong {
  color: #333;
}

.number {
  font-size: 28px;
  font-weight: bold;
  color: #409eff;
  margin: 10px 0;
}

.recent-card {
  margin-top: 20px;
}
</style> 